package jst.householdmanager.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class SQLiteHelper extends SQLiteOpenHelper {

	private static final String DATABASE_NAME = "householdmanager.db";
	private static final int DATABASE_VERSION = 1;

	public SQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(ItemsDataSource.CREATE_TABLE);
		database.execSQL(ItemCategoriesDataSource.CREATE_TABLE);
		database.execSQL(Items_in_ItemCategoriesDataSource.CREATE_TABLE);
		database.execSQL(ShopsDataSource.CREATE_TABLE);
		database.execSQL(Shops_has_ItemsDataSource.CREATE_TABLE);
		database.execSQL(PurchaseListPosDataSource.CREATE_TABLE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.w(SQLiteHelper.class.getName(), "Upgrading database from version " + oldVersion + " to " + newVersion
				+ ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + ItemsDataSource.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + ItemCategoriesDataSource.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + Items_in_ItemCategoriesDataSource.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + ShopsDataSource.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + Shops_has_ItemsDataSource.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + PurchaseListPosDataSource.TABLE_NAME);
		onCreate(db);
	}

}
